home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / misc / maplay1_2.lha / maplay / subband_layer_2.cc < prev    next >
C/C++ Source or Header  |  1994-06-23  |  47KB  |  951 lines

  1. /*
  2.  *  @(#) subband_layer_2.cc 1.8, last edit: 6/15/94 16:51:50
  3.  *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
  4.  *  @(#) Berlin University of Technology
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /*
  22.  *  Changes from version 1.1 to 1.2:
  23.  *    - calculation of the 3 samples contained in one groupcode is now done
  24.  *      through lookup tables, no more integer modulo or division required.
  25.  *      table_*_quantizationsteps[] arrays replaced by
  26.  *      table_*_groupingtables[] arrays
  27.  
  28.  *    - scalefactors itself instead of scalefactor indices are stored in
  29.  *      SubbandLayer2... objects
  30.  *    - check for small values in [-1.0E-7, 1.0E-7] removed, because the
  31.  *      test itself was slower than some SynthesisFilter::input_sample() calls
  32.  *    - check for illegal scalefactor index 63 removed
  33.  */
  34.  
  35. #include <stdlib.h>
  36. #include "subband_layer_2.h"
  37. #include "scalefactors.h"
  38.  
  39.  
  40. static const real grouping_5bits[27 * 3] =
  41. // this table contains 3 requantized samples for each legal codeword
  42. // when grouped in 5 bits, i.e. 3 quantizationsteps per sample
  43. {
  44.   -2.0/3.0, -2.0/3.0, -2.0/3.0,
  45.        0.0, -2.0/3.0, -2.0/3.0,
  46.    2.0/3.0, -2.0/3.0, -2.0/3.0,
  47.   -2.0/3.0,      0.0, -2.0/3.0,
  48.        0.0,      0.0, -2.0/3.0,
  49.    2.0/3.0,      0.0, -2.0/3.0,
  50.   -2.0/3.0,  2.0/3.0, -2.0/3.0,
  51.        0.0,  2.0/3.0, -2.0/3.0,
  52.    2.0/3.0,  2.0/3.0, -2.0/3.0,
  53.   -2.0/3.0, -2.0/3.0,      0.0,
  54.        0.0, -2.0/3.0,      0.0,
  55.    2.0/3.0, -2.0/3.0,      0.0,
  56.   -2.0/3.0,      0.0,      0.0,
  57.        0.0,      0.0,      0.0,
  58.    2.0/3.0,      0.0,      0.0,
  59.   -2.0/3.0,  2.0/3.0,      0.0,
  60.        0.0,  2.0/3.0,      0.0,
  61.    2.0/3.0,  2.0/3.0,      0.0,
  62.   -2.0/3.0, -2.0/3.0,  2.0/3.0,
  63.        0.0, -2.0/3.0,  2.0/3.0,
  64.    2.0/3.0, -2.0/3.0,  2.0/3.0,
  65.   -2.0/3.0,      0.0,  2.0/3.0,
  66.        0.0,      0.0,  2.0/3.0,
  67.    2.0/3.0,      0.0,  2.0/3.0,
  68.   -2.0/3.0,  2.0/3.0,  2.0/3.0,
  69.        0.0,  2.0/3.0,  2.0/3.0,
  70.    2.0/3.0,  2.0/3.0,  2.0/3.0
  71. };
  72.  
  73. static const real grouping_7bits[125 * 3] =
  74. // this table contains 3 requantized samples for each legal codeword
  75. // when grouped in 7 bits, i.e. 5 quantizationsteps per sample
  76. {
  77.   -0.8, -0.8, -0.8,   -0.4, -0.8, -0.8,    0.0, -0.8, -0.8,    0.4, -0.8, -0.8,    0.8, -0.8, -0.8,
  78.   -0.8, -0.4, -0.8,   -0.4, -0.4, -0.8,    0.0, -0.4, -0.8,    0.4, -0.4, -0.8,    0.8, -0.4, -0.8,
  79.   -0.8,  0.0, -0.8,   -0.4,  0.0, -0.8,    0.0,  0.0, -0.8,    0.4,  0.0, -0.8,    0.8,  0.0, -0.8,
  80.   -0.8,  0.4, -0.8,   -0.4,  0.4, -0.8,    0.0,  0.4, -0.8,    0.4,  0.4, -0.8,    0.8,  0.4, -0.8,
  81.   -0.8,  0.8, -0.8,   -0.4,  0.8, -0.8,    0.0,  0.8, -0.8,    0.4,  0.8, -0.8,    0.8,  0.8, -0.8,
  82.   -0.8, -0.8, -0.4,   -0.4, -0.8, -0.4,    0.0, -0.8, -0.4,    0.4, -0.8, -0.4,    0.8, -0.8, -0.4,
  83.   -0.8, -0.4, -0.4,   -0.4, -0.4, -0.4,    0.0, -0.4, -0.4,    0.4, -0.4, -0.4,    0.8, -0.4, -0.4,
  84.   -0.8,  0.0, -0.4,   -0.4,  0.0, -0.4,    0.0,  0.0, -0.4,    0.4,  0.0, -0.4,    0.8,  0.0, -0.4,
  85.   -0.8,  0.4, -0.4,   -0.4,  0.4, -0.4,    0.0,  0.4, -0.4,    0.4,  0.4, -0.4,    0.8,  0.4, -0.4,
  86.   -0.8,  0.8, -0.4,   -0.4,  0.8, -0.4,    0.0,  0.8, -0.4,    0.4,  0.8, -0.4,    0.8,  0.8, -0.4,
  87.   -0.8, -0.8,  0.0,   -0.4, -0.8,  0.0,    0.0, -0.8,  0.0,    0.4, -0.8,  0.0,    0.8, -0.8,  0.0,
  88.   -0.8, -0.4,  0.0,   -0.4, -0.4,  0.0,    0.0, -0.4,  0.0,    0.4, -0.4,  0.0,    0.8, -0.4,  0.0,
  89.   -0.8,  0.0,  0.0,   -0.4,  0.0,  0.0,    0.0,  0.0,  0.0,    0.4,  0.0,  0.0,    0.8,  0.0,  0.0,
  90.   -0.8,  0.4,  0.0,   -0.4,  0.4,  0.0,    0.0,  0.4,  0.0,    0.4,  0.4,  0.0,    0.8,  0.4,  0.0,
  91.   -0.8,  0.8,  0.0,   -0.4,  0.8,  0.0,    0.0,  0.8,  0.0,    0.4,  0.8,  0.0,    0.8,  0.8,  0.0,
  92.   -0.8, -0.8,  0.4,   -0.4, -0.8,  0.4,    0.0, -0.8,  0.4,    0.4, -0.8,  0.4,    0.8, -0.8,  0.4,
  93.   -0.8, -0.4,  0.4,   -0.4, -0.4,  0.4,    0.0, -0.4,  0.4,    0.4, -0.4,  0.4,    0.8, -0.4,  0.4,
  94.   -0.8,  0.0,  0.4,   -0.4,  0.0,  0.4,    0.0,  0.0,  0.4,    0.4,  0.0,  0.4,    0.8,  0.0,  0.4,
  95.   -0.8,  0.4,  0.4,   -0.4,  0.4,  0.4,    0.0,  0.4,  0.4,    0.4,  0.4,  0.4,    0.8,  0.4,  0.4,
  96.   -0.8,  0.8,  0.4,   -0.4,  0.8,  0.4,    0.0,  0.8,  0.4,    0.4,  0.8,  0.4,    0.8,  0.8,  0.4,
  97.   -0.8, -0.8,  0.8,   -0.4, -0.8,  0.8,    0.0, -0.8,  0.8,    0.4, -0.8,  0.8,    0.8, -0.8,  0.8,
  98.   -0.8, -0.4,  0.8,   -0.4, -0.4,  0.8,    0.0, -0.4,  0.8,    0.4, -0.4,  0.8,    0.8, -0.4,  0.8,
  99.   -0.8,  0.0,  0.8,   -0.4,  0.0,  0.8,    0.0,  0.0,  0.8,    0.4,  0.0,  0.8,    0.8,  0.0,  0.8,
  100.   -0.8,  0.4,  0.8,   -0.4,  0.4,  0.8,    0.0,  0.4,  0.8,    0.4,  0.4,  0.8,    0.8,  0.4,  0.8,
  101.   -0.8,  0.8,  0.8,   -0.4,  0.8,  0.8,    0.0,  0.8,  0.8,    0.4,  0.8,  0.8,    0.8,  0.8,  0.8
  102. };
  103.  
  104. static const real grouping_10bits[729 * 3] =
  105. // this table contains 3 requantized samples for each legal codeword
  106. // when grouped in 10 bits, i.e. 9 quantizationsteps per sample
  107. {
  108.   -8.0/9.0, -8.0/9.0, -8.0/9.0,   -6.0/9.0, -8.0/9.0, -8.0/9.0,   -4.0/9.0, -8.0/9.0, -8.0/9.0,
  109.   -2.0/9.0, -8.0/9.0, -8.0/9.0,        0.0, -8.0/9.0, -8.0/9.0,    2.0/9.0, -8.0/9.0, -8.0/9.0,
  110.    4.0/9.0, -8.0/9.0, -8.0/9.0,    6.0/9.0, -8.0/9.0, -8.0/9.0,    8.0/9.0, -8.0/9.0, -8.0/9.0,
  111.   -8.0/9.0, -6.0/9.0, -8.0/9.0,   -6.0/9.0, -6.0/9.0, -8.0/9.0,   -4.0/9.0, -6.0/9.0, -8.0/9.0,
  112.   -2.0/9.0, -6.0/9.0, -8.0/9.0,        0.0, -6.0/9.0, -8.0/9.0,    2.0/9.0, -6.0/9.0, -8.0/9.0,
  113.    4.0/9.0, -6.0/9.0, -8.0/9.0,    6.0/9.0, -6.0/9.0, -8.0/9.0,    8.0/9.0, -6.0/9.0, -8.0/9.0,
  114.   -8.0/9.0, -4.0/9.0, -8.0/9.0,   -6.0/9.0, -4.0/9.0, -8.0/9.0,   -4.0/9.0, -4.0/9.0, -8.0/9.0,
  115.   -2.0/9.0, -4.0/9.0, -8.0/9.0,        0.0, -4.0/9.0, -8.0/9.0,    2.0/9.0, -4.0/9.0, -8.0/9.0,
  116.    4.0/9.0, -4.0/9.0, -8.0/9.0,    6.0/9.0, -4.0/9.0, -8.0/9.0,    8.0/9.0, -4.0/9.0, -8.0/9.0,
  117.   -8.0/9.0, -2.0/9.0, -8.0/9.0,   -6.0/9.0, -2.0/9.0, -8.0/9.0,   -4.0/9.0, -2.0/9.0, -8.0/9.0,
  118.   -2.0/9.0, -2.0/9.0, -8.0/9.0,        0.0, -2.0/9.0, -8.0/9.0,    2.0/9.0, -2.0/9.0, -8.0/9.0,
  119.    4.0/9.0, -2.0/9.0, -8.0/9.0,    6.0/9.0, -2.0/9.0, -8.0/9.0,    8.0/9.0, -2.0/9.0, -8.0/9.0,
  120.   -8.0/9.0,      0.0, -8.0/9.0,   -6.0/9.0,      0.0, -8.0/9.0,   -4.0/9.0,      0.0, -8.0/9.0,
  121.   -2.0/9.0,      0.0, -8.0/9.0,        0.0,      0.0, -8.0/9.0,    2.0/9.0,      0.0, -8.0/9.0,
  122.    4.0/9.0,      0.0, -8.0/9.0,    6.0/9.0,      0.0, -8.0/9.0,    8.0/9.0,      0.0, -8.0/9.0,
  123.   -8.0/9.0,  2.0/9.0, -8.0/9.0,   -6.0/9.0,  2.0/9.0, -8.0/9.0,   -4.0/9.0,  2.0/9.0, -8.0/9.0,
  124.   -2.0/9.0,  2.0/9.0, -8.0/9.0,        0.0,  2.0/9.0, -8.0/9.0,    2.0/9.0,  2.0/9.0, -8.0/9.0,
  125.    4.0/9.0,  2.0/9.0, -8.0/9.0,    6.0/9.0,  2.0/9.0, -8.0/9.0,    8.0/9.0,  2.0/9.0, -8.0/9.0,
  126.   -8.0/9.0,  4.0/9.0, -8.0/9.0,   -6.0/9.0,  4.0/9.0, -8.0/9.0,   -4.0/9.0,  4.0/9.0, -8.0/9.0,
  127.   -2.0/9.0,  4.0/9.0, -8.0/9.0,        0.0,  4.0/9.0, -8.0/9.0,    2.0/9.0,  4.0/9.0, -8.0/9.0,
  128.    4.0/9.0,  4.0/9.0, -8.0/9.0,    6.0/9.0,  4.0/9.0, -8.0/9.0,    8.0/9.0,  4.0/9.0, -8.0/9.0,
  129.   -8.0/9.0,  6.0/9.0, -8.0/9.0,   -6.0/9.0,  6.0/9.0, -8.0/9.0,   -4.0/9.0,  6.0/9.0, -8.0/9.0,
  130.   -2.0/9.0,  6.0/9.0, -8.0/9.0,        0.0,  6.0/9.0, -8.0/9.0,    2.0/9.0,  6.0/9.0, -8.0/9.0,
  131.    4.0/9.0,  6.0/9.0, -8.0/9.0,    6.0/9.0,  6.0/9.0, -8.0/9.0,    8.0/9.0,  6.0/9.0, -8.0/9.0,
  132.   -8.0/9.0,  8.0/9.0, -8.0/9.0,   -6.0/9.0,  8.0/9.0, -8.0/9.0,   -4.0/9.0,  8.0/9.0, -8.0/9.0,
  133.   -2.0/9.0,  8.0/9.0, -8.0/9.0,        0.0,  8.0/9.0, -8.0/9.0,    2.0/9.0,  8.0/9.0, -8.0/9.0,
  134.    4.0/9.0,  8.0/9.0, -8.0/9.0,    6.0/9.0,  8.0/9.0, -8.0/9.0,    8.0/9.0,  8.0/9.0, -8.0/9.0,
  135.   -8.0/9.0, -8.0/9.0, -6.0/9.0,   -6.0/9.0, -8.0/9.0, -6.0/9.0,   -4.0/9.0, -8.0/9.0, -6.0/9.0,
  136.   -2.0/9.0, -8.0/9.0, -6.0/9.0,        0.0, -8.0/9.0, -6.0/9.0,    2.0/9.0, -8.0/9.0, -6.0/9.0,
  137.    4.0/9.0, -8.0/9.0, -6.0/9.0,    6.0/9.0, -8.0/9.0, -6.0/9.0,    8.0/9.0, -8.0/9.0, -6.0/9.0,
  138.   -8.0/9.0, -6.0/9.0, -6.0/9.0,   -6.0/9.0, -6.0/9.0, -6.0/9.0,   -4.0/9.0, -6.0/9.0, -6.0/9.0,
  139.   -2.0/9.0, -6.0/9.0, -6.0/9.0,        0.0, -6.0/9.0, -6.0/9.0,    2.0/9.0, -6.0/9.0, -6.0/9.0,
  140.    4.0/9.0, -6.0/9.0, -6.0/9.0,    6.0/9.0, -6.0/9.0, -6.0/9.0,    8.0/9.0, -6.0/9.0, -6.0/9.0,
  141.   -8.0/9.0, -4.0/9.0, -6.0/9.0,   -6.0/9.0, -4.0/9.0, -6.0/9.0,   -4.0/9.0, -4.0/9.0, -6.0/9.0,
  142.   -2.0/9.0, -4.0/9.0, -6.0/9.0,        0.0, -4.0/9.0, -6.0/9.0,    2.0/9.0, -4.0/9.0, -6.0/9.0,
  143.    4.0/9.0, -4.0/9.0, -6.0/9.0,    6.0/9.0, -4.0/9.0, -6.0/9.0,    8.0/9.0, -4.0/9.0, -6.0/9.0,
  144.   -8.0/9.0, -2.0/9.0, -6.0/9.0,   -6.0/9.0, -2.0/9.0, -6.0/9.0,   -4.0/9.0, -2.0/9.0, -6.0/9.0,
  145.   -2.0/9.0, -2.0/9.0, -6.0/9.0,        0.0, -2.0/9.0, -6.0/9.0,    2.0/9.0, -2.0/9.0, -6.0/9.0,
  146.    4.0/9.0, -2.0/9.0, -6.0/9.0,    6.0/9.0, -2.0/9.0, -6.0/9.0,    8.0/9.0, -2.0/9.0, -6.0/9.0,
  147.   -8.0/9.0,      0.0, -6.0/9.0,   -6.0/9.0,      0.0, -6.0/9.0,   -4.0/9.0,      0.0, -6.0/9.0,
  148.   -2.0/9.0,      0.0, -6.0/9.0,        0.0,      0.0, -6.0/9.0,    2.0/9.0,      0.0, -6.0/9.0,
  149.    4.0/9.0,      0.0, -6.0/9.0,    6.0/9.0,      0.0, -6.0/9.0,    8.0/9.0,      0.0, -6.0/9.0,
  150.   -8.0/9.0,  2.0/9.0, -6.0/9.0,   -6.0/9.0,  2.0/9.0, -6.0/9.0,   -4.0/9.0,  2.0/9.0, -6.0/9.0,
  151.   -2.0/9.0,  2.0/9.0, -6.0/9.0,        0.0,  2.0/9.0, -6.0/9.0,    2.0/9.0,  2.0/9.0, -6.0/9.0,
  152.    4.0/9.0,  2.0/9.0, -6.0/9.0,    6.0/9.0,  2.0/9.0, -6.0/9.0,    8.0/9.0,  2.0/9.0, -6.0/9.0,
  153.   -8.0/9.0,  4.0/9.0, -6.0/9.0,   -6.0/9.0,  4.0/9.0, -6.0/9.0,   -4.0/9.0,  4.0/9.0, -6.0/9.0,
  154.   -2.0/9.0,  4.0/9.0, -6.0/9.0,        0.0,  4.0/9.0, -6.0/9.0,    2.0/9.0,  4.0/9.0, -6.0/9.0,
  155.    4.0/9.0,  4.0/9.0, -6.0/9.0,    6.0/9.0,  4.0/9.0, -6.0/9.0,    8.0/9.0,  4.0/9.0, -6.0/9.0,
  156.   -8.0/9.0,  6.0/9.0, -6.0/9.0,   -6.0/9.0,  6.0/9.0, -6.0/9.0,   -4.0/9.0,  6.0/9.0, -6.0/9.0,
  157.   -2.0/9.0,  6.0/9.0, -6.0/9.0,        0.0,  6.0/9.0, -6.0/9.0,    2.0/9.0,  6.0/9.0, -6.0/9.0,
  158.    4.0/9.0,  6.0/9.0, -6.0/9.0,    6.0/9.0,  6.0/9.0, -6.0/9.0,    8.0/9.0,  6.0/9.0, -6.0/9.0,
  159.   -8.0/9.0,  8.0/9.0, -6.0/9.0,   -6.0/9.0,  8.0/9.0, -6.0/9.0,   -4.0/9.0,  8.0/9.0, -6.0/9.0,
  160.   -2.0/9.0,  8.0/9.0, -6.0/9.0,        0.0,  8.0/9.0, -6.0/9.0,    2.0/9.0,  8.0/9.0, -6.0/9.0,
  161.    4.0/9.0,  8.0/9.0, -6.0/9.0,    6.0/9.0,  8.0/9.0, -6.0/9.0,    8.0/9.0,  8.0/9.0, -6.0/9.0,
  162.   -8.0/9.0, -8.0/9.0, -4.0/9.0,   -6.0/9.0, -8.0/9.0, -4.0/9.0,   -4.0/9.0, -8.0/9.0, -4.0/9.0,
  163.   -2.0/9.0, -8.0/9.0, -4.0/9.0,        0.0, -8.0/9.0, -4.0/9.0,    2.0/9.0, -8.0/9.0, -4.0/9.0,
  164.    4.0/9.0, -8.0/9.0, -4.0/9.0,    6.0/9.0, -8.0/9.0, -4.0/9.0,    8.0/9.0, -8.0/9.0, -4.0/9.0,
  165.   -8.0/9.0, -6.0/9.0, -4.0/9.0,   -6.0/9.0, -6.0/9.0, -4.0/9.0,   -4.0/9.0, -6.0/9.0, -4.0/9.0,
  166.   -2.0/9.0, -6.0/9.0, -4.0/9.0,        0.0, -6.0/9.0, -4.0/9.0,    2.0/9.0, -6.0/9.0, -4.0/9.0,
  167.    4.0/9.0, -6.0/9.0, -4.0/9.0,    6.0/9.0, -6.0/9.0, -4.0/9.0,    8.0/9.0, -6.0/9.0, -4.0/9.0,
  168.   -8.0/9.0, -4.0/9.0, -4.0/9.0,   -6.0/9.0, -4.0/9.0, -4.0/9.0,   -4.0/9.0, -4.0/9.0, -4.0/9.0,
  169.   -2.0/9.0, -4.0/9.0, -4.0/9.0,        0.0, -4.0/9.0, -4.0/9.0,    2.0/9.0, -4.0/9.0, -4.0/9.0,
  170.    4.0/9.0, -4.0/9.0, -4.0/9.0,    6.0/9.0, -4.0/9.0, -4.0/9.0,    8.0/9.0, -4.0/9.0, -4.0/9.0,
  171.   -8.0/9.0, -2.0/9.0, -4.0/9.0,   -6.0/9.0, -2.0/9.0, -4.0/9.0,   -4.0/9.0, -2.0/9.0, -4.0/9.0,
  172.   -2.0/9.0, -2.0/9.0, -4.0/9.0,        0.0, -2.0/9.0, -4.0/9.0,    2.0/9.0, -2.0/9.0, -4.0/9.0,
  173.    4.0/9.0, -2.0/9.0, -4.0/9.0,    6.0/9.0, -2.0/9.0, -4.0/9.0,    8.0/9.0, -2.0/9.0, -4.0/9.0,
  174.   -8.0/9.0,      0.0, -4.0/9.0,   -6.0/9.0,      0.0, -4.0/9.0,   -4.0/9.0,      0.0, -4.0/9.0,
  175.   -2.0/9.0,      0.0, -4.0/9.0,        0.0,      0.0, -4.0/9.0,    2.0/9.0,      0.0, -4.0/9.0,
  176.    4.0/9.0,      0.0, -4.0/9.0,    6.0/9.0,      0.0, -4.0/9.0,    8.0/9.0,      0.0, -4.0/9.0,
  177.   -8.0/9.0,  2.0/9.0, -4.0/9.0,   -6.0/9.0,  2.0/9.0, -4.0/9.0,   -4.0/9.0,  2.0/9.0, -4.0/9.0,
  178.   -2.0/9.0,  2.0/9.0, -4.0/9.0,        0.0,  2.0/9.0, -4.0/9.0,    2.0/9.0,  2.0/9.0, -4.0/9.0,
  179.    4.0/9.0,  2.0/9.0, -4.0/9.0,    6.0/9.0,  2.0/9.0, -4.0/9.0,    8.0/9.0,  2.0/9.0, -4.0/9.0,
  180.   -8.0/9.0,  4.0/9.0, -4.0/9.0,   -6.0/9.0,  4.0/9.0, -4.0/9.0,   -4.0/9.0,  4.0/9.0, -4.0/9.0,
  181.   -2.0/9.0,  4.0/9.0, -4.0/9.0,        0.0,  4.0/9.0, -4.0/9.0,    2.0/9.0,  4.0/9.0, -4.0/9.0,
  182.    4.0/9.0,  4.0/9.0, -4.0/9.0,    6.0/9.0,  4.0/9.0, -4.0/9.0,    8.0/9.0,  4.0/9.0, -4.0/9.0,
  183.   -8.0/9.0,  6.0/9.0, -4.0/9.0,   -6.0/9.0,  6.0/9.0, -4.0/9.0,   -4.0/9.0,  6.0/9.0, -4.0/9.0,
  184.   -2.0/9.0,  6.0/9.0, -4.0/9.0,        0.0,  6.0/9.0, -4.0/9.0,    2.0/9.0,  6.0/9.0, -4.0/9.0,
  185.    4.0/9.0,  6.0/9.0, -4.0/9.0,    6.0/9.0,  6.0/9.0, -4.0/9.0,    8.0/9.0,  6.0/9.0, -4.0/9.0,
  186.   -8.0/9.0,  8.0/9.0, -4.0/9.0,   -6.0/9.0,  8.0/9.0, -4.0/9.0,   -4.0/9.0,  8.0/9.0, -4.0/9.0,
  187.   -2.0/9.0,  8.0/9.0, -4.0/9.0,        0.0,  8.0/9.0, -4.0/9.0,    2.0/9.0,  8.0/9.0, -4.0/9.0,
  188.    4.0/9.0,  8.0/9.0, -4.0/9.0,    6.0/9.0,  8.0/9.0, -4.0/9.0,    8.0/9.0,  8.0/9.0, -4.0/9.0,
  189.   -8.0/9.0, -8.0/9.0, -2.0/9.0,   -6.0/9.0, -8.0/9.0, -2.0/9.0,   -4.0/9.0, -8.0/9.0, -2.0/9.0,
  190.   -2.0/9.0, -8.0/9.0, -2.0/9.0,        0.0, -8.0/9.0, -2.0/9.0,    2.0/9.0, -8.0/9.0, -2.0/9.0,
  191.    4.0/9.0, -8.0/9.0, -2.0/9.0,    6.0/9.0, -8.0/9.0, -2.0/9.0,    8.0/9.0, -8.0/9.0, -2.0/9.0,
  192.   -8.0/9.0, -6.0/9.0, -2.0/9.0,   -6.0/9.0, -6.0/9.0, -2.0/9.0,   -4.0/9.0, -6.0/9.0, -2.0/9.0,
  193.   -2.0/9.0, -6.0/9.0, -2.0/9.0,        0.0, -6.0/9.0, -2.0/9.0,    2.0/9.0, -6.0/9.0, -2.0/9.0,
  194.    4.0/9.0, -6.0/9.0, -2.0/9.0,    6.0/9.0, -6.0/9.0, -2.0/9.0,    8.0/9.0, -6.0/9.0, -2.0/9.0,
  195.   -8.0/9.0, -4.0/9.0, -2.0/9.0,   -6.0/9.0, -4.0/9.0, -2.0/9.0,   -4.0/9.0, -4.0/9.0, -2.0/9.0,
  196.   -2.0/9.0, -4.0/9.0, -2.0/9.0,        0.0, -4.0/9.0, -2.0/9.0,    2.0/9.0, -4.0/9.0, -2.0/9.0,
  197.    4.0/9.0, -4.0/9.0, -2.0/9.0,    6.0/9.0, -4.0/9.0, -2.0/9.0,    8.0/9.0, -4.0/9.0, -2.0/9.0,
  198.   -8.0/9.0, -2.0/9.0, -2.0/9.0,   -6.0/9.0, -2.0/9.0, -2.0/9.0,   -4.0/9.0, -2.0/9.0, -2.0/9.0,
  199.   -2.0/9.0, -2.0/9.0, -2.0/9.0,        0.0, -2.0/9.0, -2.0/9.0,    2.0/9.0, -2.0/9.0, -2.0/9.0,
  200.    4.0/9.0, -2.0/9.0, -2.0/9.0,    6.0/9.0, -2.0/9.0, -2.0/9.0,    8.0/9.0, -2.0/9.0, -2.0/9.0,
  201.   -8.0/9.0,      0.0, -2.0/9.0,   -6.0/9.0,      0.0, -2.0/9.0,   -4.0/9.0,      0.0, -2.0/9.0,
  202.   -2.0/9.0,      0.0, -2.0/9.0,        0.0,      0.0, -2.0/9.0,    2.0/9.0,      0.0, -2.0/9.0,
  203.    4.0/9.0,      0.0, -2.0/9.0,    6.0/9.0,      0.0, -2.0/9.0,    8.0/9.0,      0.0, -2.0/9.0,
  204.   -8.0/9.0,  2.0/9.0, -2.0/9.0,   -6.0/9.0,  2.0/9.0, -2.0/9.0,   -4.0/9.0,  2.0/9.0, -2.0/9.0,
  205.   -2.0/9.0,  2.0/9.0, -2.0/9.0,        0.0,  2.0/9.0, -2.0/9.0,    2.0/9.0,  2.0/9.0, -2.0/9.0,
  206.    4.0/9.0,  2.0/9.0, -2.0/9.0,    6.0/9.0,  2.0/9.0, -2.0/9.0,    8.0/9.0,  2.0/9.0, -2.0/9.0,
  207.   -8.0/9.0,  4.0/9.0, -2.0/9.0,   -6.0/9.0,  4.0/9.0, -2.0/9.0,   -4.0/9.0,  4.0/9.0, -2.0/9.0,
  208.   -2.0/9.0,  4.0/9.0, -2.0/9.0,        0.0,  4.0/9.0, -2.0/9.0,    2.0/9.0,  4.0/9.0, -2.0/9.0,
  209.    4.0/9.0,  4.0/9.0, -2.0/9.0,    6.0/9.0,  4.0/9.0, -2.0/9.0,    8.0/9.0,  4.0/9.0, -2.0/9.0,
  210.   -8.0/9.0,  6.0/9.0, -2.0/9.0,   -6.0/9.0,  6.0/9.0, -2.0/9.0,   -4.0/9.0,  6.0/9.0, -2.0/9.0,
  211.   -2.0/9.0,  6.0/9.0, -2.0/9.0,        0.0,  6.0/9.0, -2.0/9.0,    2.0/9.0,  6.0/9.0, -2.0/9.0,
  212.    4.0/9.0,  6.0/9.0, -2.0/9.0,    6.0/9.0,  6.0/9.0, -2.0/9.0,    8.0/9.0,  6.0/9.0, -2.0/9.0,
  213.   -8.0/9.0,  8.0/9.0, -2.0/9.0,   -6.0/9.0,  8.0/9.0, -2.0/9.0,   -4.0/9.0,  8.0/9.0, -2.0/9.0,
  214.   -2.0/9.0,  8.0/9.0, -2.0/9.0,        0.0,  8.0/9.0, -2.0/9.0,    2.0/9.0,  8.0/9.0, -2.0/9.0,
  215.    4.0/9.0,  8.0/9.0, -2.0/9.0,    6.0/9.0,  8.0/9.0, -2.0/9.0,    8.0/9.0,  8.0/9.0, -2.0/9.0,
  216.   -8.0/9.0, -8.0/9.0,      0.0,   -6.0/9.0, -8.0/9.0,      0.0,   -4.0/9.0, -8.0/9.0,      0.0,
  217.   -2.0/9.0, -8.0/9.0,      0.0,        0.0, -8.0/9.0,      0.0,    2.0/9.0, -8.0/9.0,      0.0,
  218.    4.0/9.0, -8.0/9.0,      0.0,    6.0/9.0, -8.0/9.0,      0.0,    8.0/9.0, -8.0/9.0,      0.0,
  219.   -8.0/9.0, -6.0/9.0,      0.0,   -6.0/9.0, -6.0/9.0,      0.0,   -4.0/9.0, -6.0/9.0,      0.0,
  220.   -2.0/9.0, -6.0/9.0,      0.0,        0.0, -6.0/9.0,      0.0,    2.0/9.0, -6.0/9.0,      0.0,
  221.    4.0/9.0, -6.0/9.0,      0.0,    6.0/9.0, -6.0/9.0,      0.0,    8.0/9.0, -6.0/9.0,      0.0,
  222.   -8.0/9.0, -4.0/9.0,      0.0,   -6.0/9.0, -4.0/9.0,      0.0,   -4.0/9.0, -4.0/9.0,      0.0,
  223.   -2.0/9.0, -4.0/9.0,      0.0,        0.0, -4.0/9.0,      0.0,    2.0/9.0, -4.0/9.0,      0.0,
  224.    4.0/9.0, -4.0/9.0,      0.0,    6.0/9.0, -4.0/9.0,      0.0,    8.0/9.0, -4.0/9.0,      0.0,
  225.   -8.0/9.0, -2.0/9.0,      0.0,   -6.0/9.0, -2.0/9.0,      0.0,   -4.0/9.0, -2.0/9.0,      0.0,
  226.   -2.0/9.0, -2.0/9.0,      0.0,        0.0, -2.0/9.0,      0.0,    2.0/9.0, -2.0/9.0,      0.0,
  227.    4.0/9.0, -2.0/9.0,      0.0,    6.0/9.0, -2.0/9.0,      0.0,    8.0/9.0, -2.0/9.0,      0.0,
  228.   -8.0/9.0,      0.0,      0.0,   -6.0/9.0,      0.0,      0.0,   -4.0/9.0,      0.0,      0.0,
  229.   -2.0/9.0,      0.0,      0.0,        0.0,      0.0,      0.0,    2.0/9.0,      0.0,      0.0,
  230.    4.0/9.0,      0.0,      0.0,    6.0/9.0,      0.0,      0.0,    8.0/9.0,      0.0,      0.0,
  231.   -8.0/9.0,  2.0/9.0,      0.0,   -6.0/9.0,  2.0/9.0,      0.0,   -4.0/9.0,  2.0/9.0,      0.0,
  232.   -2.0/9.0,  2.0/9.0,      0.0,        0.0,  2.0/9.0,      0.0,    2.0/9.0,  2.0/9.0,      0.0,
  233.    4.0/9.0,  2.0/9.0,      0.0,    6.0/9.0,  2.0/9.0,      0.0,    8.0/9.0,  2.0/9.0,      0.0,
  234.   -8.0/9.0,  4.0/9.0,      0.0,   -6.0/9.0,  4.0/9.0,      0.0,   -4.0/9.0,  4.0/9.0,      0.0,
  235.   -2.0/9.0,  4.0/9.0,      0.0,        0.0,  4.0/9.0,      0.0,    2.0/9.0,  4.0/9.0,      0.0,
  236.    4.0/9.0,  4.0/9.0,      0.0,    6.0/9.0,  4.0/9.0,      0.0,    8.0/9.0,  4.0/9.0,      0.0,
  237.   -8.0/9.0,  6.0/9.0,      0.0,   -6.0/9.0,  6.0/9.0,      0.0,   -4.0/9.0,  6.0/9.0,      0.0,
  238.   -2.0/9.0,  6.0/9.0,      0.0,        0.0,  6.0/9.0,      0.0,    2.0/9.0,  6.0/9.0,      0.0,
  239.    4.0/9.0,  6.0/9.0,      0.0,    6.0/9.0,  6.0/9.0,      0.0,    8.0/9.0,  6.0/9.0,      0.0,
  240.   -8.0/9.0,  8.0/9.0,      0.0,   -6.0/9.0,  8.0/9.0,      0.0,   -4.0/9.0,  8.0/9.0,      0.0,
  241.   -2.0/9.0,  8.0/9.0,      0.0,        0.0,  8.0/9.0,      0.0,    2.0/9.0,  8.0/9.0,      0.0,
  242.    4.0/9.0,  8.0/9.0,      0.0,    6.0/9.0,  8.0/9.0,      0.0,    8.0/9.0,  8.0/9.0,      0.0,
  243.   -8.0/9.0, -8.0/9.0,  2.0/9.0,   -6.0/9.0, -8.0/9.0,  2.0/9.0,   -4.0/9.0, -8.0/9.0,  2.0/9.0,
  244.   -2.0/9.0, -8.0/9.0,  2.0/9.0,        0.0, -8.0/9.0,  2.0/9.0,    2.0/9.0, -8.0/9.0,  2.0/9.0,
  245.    4.0/9.0, -8.0/9.0,  2.0/9.0,    6.0/9.0, -8.0/9.0,  2.0/9.0,    8.0/9.0, -8.0/9.0,  2.0/9.0,
  246.   -8.0/9.0, -6.0/9.0,  2.0/9.0,   -6.0/9.0, -6.0/9.0,  2.0/9.0,   -4.0/9.0, -6.0/9.0,  2.0/9.0,
  247.   -2.0/9.0, -6.0/9.0,  2.0/9.0,        0.0, -6.0/9.0,  2.0/9.0,    2.0/9.0, -6.0/9.0,  2.0/9.0,
  248.    4.0/9.0, -6.0/9.0,  2.0/9.0,    6.0/9.0, -6.0/9.0,  2.0/9.0,    8.0/9.0, -6.0/9.0,  2.0/9.0,
  249.   -8.0/9.0, -4.0/9.0,  2.0/9.0,   -6.0/9.0, -4.0/9.0,  2.0/9.0,   -4.0/9.0, -4.0/9.0,  2.0/9.0,
  250.   -2.0/9.0, -4.0/9.0,  2.0/9.0,        0.0, -4.0/9.0,  2.0/9.0,    2.0/9.0, -4.0/9.0,  2.0/9.0,
  251.    4.0/9.0, -4.0/9.0,  2.0/9.0,    6.0/9.0, -4.0/9.0,  2.0/9.0,    8.0/9.0, -4.0/9.0,  2.0/9.0,
  252.   -8.0/9.0, -2.0/9.0,  2.0/9.0,   -6.0/9.0, -2.0/9.0,  2.0/9.0,   -4.0/9.0, -2.0/9.0,  2.0/9.0,
  253.   -2.0/9.0, -2.0/9.0,  2.0/9.0,        0.0, -2.0/9.0,  2.0/9.0,    2.0/9.0, -2.0/9.0,  2.0/9.0,
  254.    4.0/9.0, -2.0/9.0,  2.0/9.0,    6.0/9.0, -2.0/9.0,  2.0/9.0,    8.0/9.0, -2.0/9.0,  2.0/9.0,
  255.   -8.0/9.0,      0.0,  2.0/9.0,   -6.0/9.0,      0.0,  2.0/9.0,   -4.0/9.0,      0.0,  2.0/9.0,
  256.   -2.0/9.0,      0.0,  2.0/9.0,        0.0,      0.0,  2.0/9.0,    2.0/9.0,      0.0,  2.0/9.0,
  257.    4.0/9.0,      0.0,  2.0/9.0,    6.0/9.0,      0.0,  2.0/9.0,    8.0/9.0,      0.0,  2.0/9.0,
  258.   -8.0/9.0,  2.0/9.0,  2.0/9.0,   -6.0/9.0,  2.0/9.0,  2.0/9.0,   -4.0/9.0,  2.0/9.0,  2.0/9.0,
  259.   -2.0/9.0,  2.0/9.0,  2.0/9.0,        0.0,  2.0/9.0,  2.0/9.0,    2.0/9.0,  2.0/9.0,  2.0/9.0,
  260.    4.0/9.0,  2.0/9.0,  2.0/9.0,    6.0/9.0,  2.0/9.0,  2.0/9.0,    8.0/9.0,  2.0/9.0,  2.0/9.0,
  261.   -8.0/9.0,  4.0/9.0,  2.0/9.0,   -6.0/9.0,  4.0/9.0,  2.0/9.0,   -4.0/9.0,  4.0/9.0,  2.0/9.0,
  262.   -2.0/9.0,  4.0/9.0,  2.0/9.0,        0.0,  4.0/9.0,  2.0/9.0,    2.0/9.0,  4.0/9.0,  2.0/9.0,
  263.    4.0/9.0,  4.0/9.0,  2.0/9.0,    6.0/9.0,  4.0/9.0,  2.0/9.0,    8.0/9.0,  4.0/9.0,  2.0/9.0,
  264.   -8.0/9.0,  6.0/9.0,  2.0/9.0,   -6.0/9.0,  6.0/9.0,  2.0/9.0,   -4.0/9.0,  6.0/9.0,  2.0/9.0,
  265.   -2.0/9.0,  6.0/9.0,  2.0/9.0,        0.0,  6.0/9.0,  2.0/9.0,    2.0/9.0,  6.0/9.0,  2.0/9.0,
  266.    4.0/9.0,  6.0/9.0,  2.0/9.0,    6.0/9.0,  6.0/9.0,  2.0/9.0,    8.0/9.0,  6.0/9.0,  2.0/9.0,
  267.   -8.0/9.0,  8.0/9.0,  2.0/9.0,   -6.0/9.0,  8.0/9.0,  2.0/9.0,   -4.0/9.0,  8.0/9.0,  2.0/9.0,
  268.   -2.0/9.0,  8.0/9.0,  2.0/9.0,        0.0,  8.0/9.0,  2.0/9.0,    2.0/9.0,  8.0/9.0,  2.0/9.0,
  269.    4.0/9.0,  8.0/9.0,  2.0/9.0,    6.0/9.0,  8.0/9.0,  2.0/9.0,    8.0/9.0,  8.0/9.0,  2.0/9.0,
  270.   -8.0/9.0, -8.0/9.0,  4.0/9.0,   -6.0/9.0, -8.0/9.0,  4.0/9.0,   -4.0/9.0, -8.0/9.0,  4.0/9.0,
  271.   -2.0/9.0, -8.0/9.0,  4.0/9.0,        0.0, -8.0/9.0,  4.0/9.0,    2.0/9.0, -8.0/9.0,  4.0/9.0,
  272.    4.0/9.0, -8.0/9.0,  4.0/9.0,    6.0/9.0, -8.0/9.0,  4.0/9.0,    8.0/9.0, -8.0/9.0,  4.0/9.0,
  273.   -8.0/9.0, -6.0/9.0,  4.0/9.0,   -6.0/9.0, -6.0/9.0,  4.0/9.0,   -4.0/9.0, -6.0/9.0,  4.0/9.0,
  274.   -2.0/9.0, -6.0/9.0,  4.0/9.0,        0.0, -6.0/9.0,  4.0/9.0,    2.0/9.0, -6.0/9.0,  4.0/9.0,
  275.    4.0/9.0, -6.0/9.0,  4.0/9.0,    6.0/9.0, -6.0/9.0,  4.0/9.0,    8.0/9.0, -6.0/9.0,  4.0/9.0,
  276.   -8.0/9.0, -4.0/9.0,  4.0/9.0,   -6.0/9.0, -4.0/9.0,  4.0/9.0,   -4.0/9.0, -4.0/9.0,  4.0/9.0,
  277.   -2.0/9.0, -4.0/9.0,  4.0/9.0,        0.0, -4.0/9.0,  4.0/9.0,    2.0/9.0, -4.0/9.0,  4.0/9.0,
  278.    4.0/9.0, -4.0/9.0,  4.0/9.0,    6.0/9.0, -4.0/9.0,  4.0/9.0,    8.0/9.0, -4.0/9.0,  4.0/9.0,
  279.   -8.0/9.0, -2.0/9.0,  4.0/9.0,   -6.0/9.0, -2.0/9.0,  4.0/9.0,   -4.0/9.0, -2.0/9.0,  4.0/9.0,
  280.   -2.0/9.0, -2.0/9.0,  4.0/9.0,        0.0, -2.0/9.0,  4.0/9.0,    2.0/9.0, -2.0/9.0,  4.0/9.0,
  281.    4.0/9.0, -2.0/9.0,  4.0/9.0,    6.0/9.0, -2.0/9.0,  4.0/9.0,    8.0/9.0, -2.0/9.0,  4.0/9.0,
  282.   -8.0/9.0,      0.0,  4.0/9.0,   -6.0/9.0,      0.0,  4.0/9.0,   -4.0/9.0,      0.0,  4.0/9.0,
  283.   -2.0/9.0,      0.0,  4.0/9.0,        0.0,      0.0,  4.0/9.0,    2.0/9.0,      0.0,  4.0/9.0,
  284.    4.0/9.0,      0.0,  4.0/9.0,    6.0/9.0,      0.0,  4.0/9.0,    8.0/9.0,      0.0,  4.0/9.0,
  285.   -8.0/9.0,  2.0/9.0,  4.0/9.0,   -6.0/9.0,  2.0/9.0,  4.0/9.0,   -4.0/9.0,  2.0/9.0,  4.0/9.0,
  286.   -2.0/9.0,  2.0/9.0,  4.0/9.0,        0.0,  2.0/9.0,  4.0/9.0,    2.0/9.0,  2.0/9.0,  4.0/9.0,
  287.    4.0/9.0,  2.0/9.0,  4.0/9.0,    6.0/9.0,  2.0/9.0,  4.0/9.0,    8.0/9.0,  2.0/9.0,  4.0/9.0,
  288.   -8.0/9.0,  4.0/9.0,  4.0/9.0,   -6.0/9.0,  4.0/9.0,  4.0/9.0,   -4.0/9.0,  4.0/9.0,  4.0/9.0,
  289.   -2.0/9.0,  4.0/9.0,  4.0/9.0,        0.0,  4.0/9.0,  4.0/9.0,    2.0/9.0,  4.0/9.0,  4.0/9.0,
  290.    4.0/9.0,  4.0/9.0,  4.0/9.0,    6.0/9.0,  4.0/9.0,  4.0/9.0,    8.0/9.0,  4.0/9.0,  4.0/9.0,
  291.   -8.0/9.0,  6.0/9.0,  4.0/9.0,   -6.0/9.0,  6.0/9.0,  4.0/9.0,   -4.0/9.0,  6.0/9.0,  4.0/9.0,
  292.   -2.0/9.0,  6.0/9.0,  4.0/9.0,        0.0,  6.0/9.0,  4.0/9.0,    2.0/9.0,  6.0/9.0,  4.0/9.0,
  293.    4.0/9.0,  6.0/9.0,  4.0/9.0,    6.0/9.0,  6.0/9.0,  4.0/9.0,    8.0/9.0,  6.0/9.0,  4.0/9.0,
  294.   -8.0/9.0,  8.0/9.0,  4.0/9.0,   -6.0/9.0,  8.0/9.0,  4.0/9.0,   -4.0/9.0,  8.0/9.0,  4.0/9.0,
  295.   -2.0/9.0,  8.0/9.0,  4.0/9.0,        0.0,  8.0/9.0,  4.0/9.0,    2.0/9.0,  8.0/9.0,  4.0/9.0,
  296.    4.0/9.0,  8.0/9.0,  4.0/9.0,    6.0/9.0,  8.0/9.0,  4.0/9.0,    8.0/9.0,  8.0/9.0,  4.0/9.0,
  297.   -8.0/9.0, -8.0/9.0,  6.0/9.0,   -6.0/9.0, -8.0/9.0,  6.0/9.0,   -4.0/9.0, -8.0/9.0,  6.0/9.0,
  298.   -2.0/9.0, -8.0/9.0,  6.0/9.0,        0.0, -8.0/9.0,  6.0/9.0,    2.0/9.0, -8.0/9.0,  6.0/9.0,
  299.    4.0/9.0, -8.0/9.0,  6.0/9.0,    6.0/9.0, -8.0/9.0,  6.0/9.0,    8.0/9.0, -8.0/9.0,  6.0/9.0,
  300.   -8.0/9.0, -6.0/9.0,  6.0/9.0,   -6.0/9.0, -6.0/9.0,  6.0/9.0,   -4.0/9.0, -6.0/9.0,  6.0/9.0,
  301.   -2.0/9.0, -6.0/9.0,  6.0/9.0,        0.0, -6.0/9.0,  6.0/9.0,    2.0/9.0, -6.0/9.0,  6.0/9.0,
  302.    4.0/9.0, -6.0/9.0,  6.0/9.0,    6.0/9.0, -6.0/9.0,  6.0/9.0,    8.0/9.0, -6.0/9.0,  6.0/9.0,
  303.   -8.0/9.0, -4.0/9.0,  6.0/9.0,   -6.0/9.0, -4.0/9.0,  6.0/9.0,   -4.0/9.0, -4.0/9.0,  6.0/9.0,
  304.   -2.0/9.0, -4.0/9.0,  6.0/9.0,        0.0, -4.0/9.0,  6.0/9.0,    2.0/9.0, -4.0/9.0,  6.0/9.0,
  305.    4.0/9.0, -4.0/9.0,  6.0/9.0,    6.0/9.0, -4.0/9.0,  6.0/9.0,    8.0/9.0, -4.0/9.0,  6.0/9.0,
  306.   -8.0/9.0, -2.0/9.0,  6.0/9.0,   -6.0/9.0, -2.0/9.0,  6.0/9.0,   -4.0/9.0, -2.0/9.0,  6.0/9.0,
  307.   -2.0/9.0, -2.0/9.0,  6.0/9.0,        0.0, -2.0/9.0,  6.0/9.0,    2.0/9.0, -2.0/9.0,  6.0/9.0,
  308.    4.0/9.0, -2.0/9.0,  6.0/9.0,    6.0/9.0, -2.0/9.0,  6.0/9.0,    8.0/9.0, -2.0/9.0,  6.0/9.0,
  309.   -8.0/9.0,      0.0,  6.0/9.0,   -6.0/9.0,      0.0,  6.0/9.0,   -4.0/9.0,      0.0,  6.0/9.0,
  310.   -2.0/9.0,      0.0,  6.0/9.0,        0.0,      0.0,  6.0/9.0,    2.0/9.0,      0.0,  6.0/9.0,
  311.    4.0/9.0,      0.0,  6.0/9.0,    6.0/9.0,      0.0,  6.0/9.0,    8.0/9.0,      0.0,  6.0/9.0,
  312.   -8.0/9.0,  2.0/9.0,  6.0/9.0,   -6.0/9.0,  2.0/9.0,  6.0/9.0,   -4.0/9.0,  2.0/9.0,  6.0/9.0,
  313.   -2.0/9.0,  2.0/9.0,  6.0/9.0,        0.0,  2.0/9.0,  6.0/9.0,    2.0/9.0,  2.0/9.0,  6.0/9.0,
  314.    4.0/9.0,  2.0/9.0,  6.0/9.0,    6.0/9.0,  2.0/9.0,  6.0/9.0,    8.0/9.0,  2.0/9.0,  6.0/9.0,
  315.   -8.0/9.0,  4.0/9.0,  6.0/9.0,   -6.0/9.0,  4.0/9.0,  6.0/9.0,   -4.0/9.0,  4.0/9.0,  6.0/9.0,
  316.   -2.0/9.0,  4.0/9.0,  6.0/9.0,        0.0,  4.0/9.0,  6.0/9.0,    2.0/9.0,  4.0/9.0,  6.0/9.0,
  317.    4.0/9.0,  4.0/9.0,  6.0/9.0,    6.0/9.0,  4.0/9.0,  6.0/9.0,    8.0/9.0,  4.0/9.0,  6.0/9.0,
  318.   -8.0/9.0,  6.0/9.0,  6.0/9.0,   -6.0/9.0,  6.0/9.0,  6.0/9.0,   -4.0/9.0,  6.0/9.0,  6.0/9.0,
  319.   -2.0/9.0,  6.0/9.0,  6.0/9.0,        0.0,  6.0/9.0,  6.0/9.0,    2.0/9.0,  6.0/9.0,  6.0/9.0,
  320.    4.0/9.0,  6.0/9.0,  6.0/9.0,    6.0/9.0,  6.0/9.0,  6.0/9.0,    8.0/9.0,  6.0/9.0,  6.0/9.0,
  321.   -8.0/9.0,  8.0/9.0,  6.0/9.0,   -6.0/9.0,  8.0/9.0,  6.0/9.0,   -4.0/9.0,  8.0/9.0,  6.0/9.0,
  322.   -2.0/9.0,  8.0/9.0,  6.0/9.0,        0.0,  8.0/9.0,  6.0/9.0,    2.0/9.0,  8.0/9.0,  6.0/9.0,
  323.    4.0/9.0,  8.0/9.0,  6.0/9.0,    6.0/9.0,  8.0/9.0,  6.0/9.0,    8.0/9.0,  8.0/9.0,  6.0/9.0,
  324.   -8.0/9.0, -8.0/9.0,  8.0/9.0,   -6.0/9.0, -8.0/9.0,  8.0/9.0,   -4.0/9.0, -8.0/9.0,  8.0/9.0,
  325.   -2.0/9.0, -8.0/9.0,  8.0/9.0,        0.0, -8.0/9.0,  8.0/9.0,    2.0/9.0, -8.0/9.0,  8.0/9.0,
  326.    4.0/9.0, -8.0/9.0,  8.0/9.0,    6.0/9.0, -8.0/9.0,  8.0/9.0,    8.0/9.0, -8.0/9.0,  8.0/9.0,
  327.   -8.0/9.0, -6.0/9.0,  8.0/9.0,   -6.0/9.0, -6.0/9.0,  8.0/9.0,   -4.0/9.0, -6.0/9.0,  8.0/9.0,
  328.   -2.0/9.0, -6.0/9.0,  8.0/9.0,        0.0, -6.0/9.0,  8.0/9.0,    2.0/9.0, -6.0/9.0,  8.0/9.0,
  329.    4.0/9.0, -6.0/9.0,  8.0/9.0,    6.0/9.0, -6.0/9.0,  8.0/9.0,    8.0/9.0, -6.0/9.0,  8.0/9.0,
  330.   -8.0/9.0, -4.0/9.0,  8.0/9.0,   -6.0/9.0, -4.0/9.0,  8.0/9.0,   -4.0/9.0, -4.0/9.0,  8.0/9.0,
  331.   -2.0/9.0, -4.0/9.0,  8.0/9.0,        0.0, -4.0/9.0,  8.0/9.0,    2.0/9.0, -4.0/9.0,  8.0/9.0,
  332.    4.0/9.0, -4.0/9.0,  8.0/9.0,    6.0/9.0, -4.0/9.0,  8.0/9.0,    8.0/9.0, -4.0/9.0,  8.0/9.0,
  333.   -8.0/9.0, -2.0/9.0,  8.0/9.0,   -6.0/9.0, -2.0/9.0,  8.0/9.0,   -4.0/9.0, -2.0/9.0,  8.0/9.0,
  334.   -2.0/9.0, -2.0/9.0,  8.0/9.0,        0.0, -2.0/9.0,  8.0/9.0,    2.0/9.0, -2.0/9.0,  8.0/9.0,
  335.    4.0/9.0, -2.0/9.0,  8.0/9.0,    6.0/9.0, -2.0/9.0,  8.0/9.0,    8.0/9.0, -2.0/9.0,  8.0/9.0,
  336.   -8.0/9.0,      0.0,  8.0/9.0,   -6.0/9.0,      0.0,  8.0/9.0,   -4.0/9.0,      0.0,  8.0/9.0,
  337.   -2.0/9.0,      0.0,  8.0/9.0,        0.0,      0.0,  8.0/9.0,    2.0/9.0,      0.0,  8.0/9.0,
  338.    4.0/9.0,      0.0,  8.0/9.0,    6.0/9.0,      0.0,  8.0/9.0,    8.0/9.0,      0.0,  8.0/9.0,
  339.   -8.0/9.0,  2.0/9.0,  8.0/9.0,   -6.0/9.0,  2.0/9.0,  8.0/9.0,   -4.0/9.0,  2.0/9.0,  8.0/9.0,
  340.   -2.0/9.0,  2.0/9.0,  8.0/9.0,        0.0,  2.0/9.0,  8.0/9.0,    2.0/9.0,  2.0/9.0,  8.0/9.0,
  341.    4.0/9.0,  2.0/9.0,  8.0/9.0,    6.0/9.0,  2.0/9.0,  8.0/9.0,    8.0/9.0,  2.0/9.0,  8.0/9.0,
  342.   -8.0/9.0,  4.0/9.0,  8.0/9.0,   -6.0/9.0,  4.0/9.0,  8.0/9.0,   -4.0/9.0,  4.0/9.0,  8.0/9.0,
  343.   -2.0/9.0,  4.0/9.0,  8.0/9.0,        0.0,  4.0/9.0,  8.0/9.0,    2.0/9.0,  4.0/9.0,  8.0/9.0,
  344.    4.0/9.0,  4.0/9.0,  8.0/9.0,    6.0/9.0,  4.0/9.0,  8.0/9.0,    8.0/9.0,  4.0/9.0,  8.0/9.0,
  345.   -8.0/9.0,  6.0/9.0,  8.0/9.0,   -6.0/9.0,  6.0/9.0,  8.0/9.0,   -4.0/9.0,  6.0/9.0,  8.0/9.0,
  346.   -2.0/9.0,  6.0/9.0,  8.0/9.0,        0.0,  6.0/9.0,  8.0/9.0,    2.0/9.0,  6.0/9.0,  8.0/9.0,
  347.    4.0/9.0,  6.0/9.0,  8.0/9.0,    6.0/9.0,  6.0/9.0,  8.0/9.0,    8.0/9.0,  6.0/9.0,  8.0/9.0,
  348.   -8.0/9.0,  8.0/9.0,  8.0/9.0,   -6.0/9.0,  8.0/9.0,  8.0/9.0,   -4.0/9.0,  8.0/9.0,  8.0/9.0,
  349.   -2.0/9.0,  8.0/9.0,  8.0/9.0,        0.0,  8.0/9.0,  8.0/9.0,    2.0/9.0,  8.0/9.0,  8.0/9.0,
  350.    4.0/9.0,  8.0/9.0,  8.0/9.0,    6.0/9.0,  8.0/9.0,  8.0/9.0,    8.0/9.0,  8.0/9.0,  8.0/9.0
  351. };
  352.  
  353.  
  354. // data taken from ISO/IEC DIS 11172, Annexes 3-B.2[abcd] and 3-B.4:
  355.  
  356. // subbands 0-2 in tables 3-B.2a and 2b: (index is allocation)
  357. static const uint32 table_ab1_codelength[16] =
  358.   // bits per codeword
  359. { 0, 5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
  360.  
  361. static const real *table_ab1_groupingtables[16] =
  362.   // pointer to sample grouping table, or NULL-pointer if ungrouped
  363. { 0, grouping_5bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  364.  
  365. static const real table_ab1_factor[16] =
  366.   // factor for requantization: (real)sample * factor - 1.0 gives requantized sample
  367. { 0.0, 1.0/2.0, 1.0/4.0, 1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0,
  368.   1.0/128.0, 1.0/256.0, 1.0/512.0, 1.0/1024.0, 1.0/2048.0,
  369.   1.0/4096.0, 1.0/8192.0, 1.0/16384.0, 1.0/32768.0 };
  370.  
  371. static const real table_ab1_c[16] =
  372.   // factor c for requantization from table 3-B.4
  373. { 0.0,           1.33333333333, 1.14285714286, 1.06666666666, 1.03225806452,
  374.   1.01587301587, 1.00787401575, 1.00392156863, 1.00195694716, 1.00097751711,
  375.   1.00048851979, 1.00024420024, 1.00012208522, 1.00006103888, 1.00003051851,
  376.   1.00001525902 };
  377. static const real table_ab1_d[16] =
  378.   // addend d for requantization from table 3-B.4
  379. { 0.0,           0.50000000000, 0.25000000000, 0.12500000000, 0.06250000000,
  380.   0.03125000000, 0.01562500000, 0.00781250000, 0.00390625000, 0.00195312500,
  381.   0.00097656250, 0.00048828125, 0.00024414063, 0.00012207031, 0.00006103516,
  382.   0.00003051758 };
  383.  
  384. // subbands 3-... tables 3-B.2a and 2b:
  385. static const real *table_ab234_groupingtables[16] =
  386. { 0, grouping_5bits, grouping_7bits, 0, grouping_10bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  387.  
  388. // subbands 3-10 in tables 3-B.2a and 2b:
  389. static const uint32 table_ab2_codelength[16] =
  390. { 0, 5, 7, 3, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16 };
  391. static const real table_ab2_factor[16] =
  392. { 0.0, 1.0/2.0, 1.0/4.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0,
  393.   1.0/32.0, 1.0/64.0, 1.0/128.0, 1.0/256.0, 1.0/512.0,
  394.   1.0/1024.0, 1.0/2048.0, 1.0/4096.0, 1.0/32768.0 };
  395. static const real table_ab2_c[16] =
  396. { 0.0,           1.33333333333, 1.60000000000, 1.14285714286, 1.77777777777,
  397.   1.06666666666, 1.03225806452, 1.01587301587, 1.00787401575, 1.00392156863,
  398.   1.00195694716, 1.00097751711, 1.00048851979, 1.00024420024, 1.00012208522,
  399.   1.00001525902 };
  400. static const real table_ab2_d[16] =
  401. { 0.0,           0.50000000000, 0.50000000000, 0.25000000000, 0.50000000000,
  402.   0.12500000000, 0.06250000000, 0.03125000000, 0.01562500000, 0.00781250000,
  403.   0.00390625000, 0.00195312500, 0.00097656250, 0.00048828125, 0.00024414063,
  404.   0.00003051758 };
  405.  
  406. // subbands 11-22 in tables 3-B.2a and 2b:
  407. static const uint32 table_ab3_codelength[8] = { 0, 5, 7, 3, 10, 4, 5, 16 };
  408. static const real table_ab3_factor[8] =
  409. { 0.0, 1.0/2.0, 1.0/4.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0, 1.0/32768.0 };
  410. static const real table_ab3_c[8] =
  411. { 0.0,           1.33333333333, 1.60000000000, 1.14285714286, 1.77777777777,
  412.   1.06666666666, 1.03225806452, 1.00001525902 };
  413. static const real table_ab3_d[8] =
  414. { 0.0,           0.50000000000, 0.50000000000, 0.25000000000, 0.50000000000,
  415.   0.12500000000, 0.06250000000, 0.00003051758 };
  416.  
  417. // subbands 23-... in tables 3-B.2a and 2b:
  418. static const uint32 table_ab4_codelength[4] = { 0, 5, 7, 16 };
  419. static const real table_ab4_factor[8] = { 0.0, 1.0/2.0, 1.0/4.0, 1.0/32768.0 };
  420. static const real table_ab4_c[4] = { 0.0, 1.33333333333, 1.60000000000, 1.00001525902 };
  421. static const real table_ab4_d[4] = { 0.0, 0.50000000000, 0.50000000000, 0.00003051758 };
  422.  
  423. // subbands in tables 3-B.2c and 2d:
  424. static const uint32 table_cd_codelength[16] =
  425. { 0, 5, 7, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  426. static const real *table_cd_groupingtables[16] =
  427. { 0, grouping_5bits, grouping_7bits, grouping_10bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  428. static const real table_cd_factor[16] =
  429. { 0.0, 1.0/2.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0,
  430.   1.0/128.0, 1.0/256.0, 1.0/512.0, 1.0/1024.0, 1.0/2048.0, 1.0/4096.0,
  431.   1.0/8192.0, 1.0/16384.0 };
  432. static const real table_cd_c[16] =
  433. { 0.0,           1.33333333333, 1.60000000000, 1.77777777777, 1.06666666666,
  434.   1.03225806452, 1.01587301587, 1.00787401575, 1.00392156863, 1.00195694716,
  435.   1.00097751711, 1.00048851979, 1.00024420024, 1.00012208522, 1.00006103888,
  436.   1.00003051851 };
  437. static const real table_cd_d[16] =
  438. { 0.0,           0.50000000000, 0.50000000000, 0.50000000000, 0.12500000000,
  439.   0.06250000000, 0.03125000000, 0.01562500000, 0.00781250000, 0.00390625000,
  440.   0.00195312500, 0.00097656250, 0.00048828125, 0.00024414063, 0.00012207031,
  441.   0.00006103516 };
  442.  
  443.  
  444.  
  445. /**********************/    // used for single channel mode
  446. /*** Standard Class ***/    // and in derived class for intensity
  447. /**********************/    // stereo mode
  448.  
  449. SubbandLayer2::SubbandLayer2 (uint32 subbandnumber)
  450. {
  451.   this->subbandnumber = subbandnumber;
  452.   groupnumber = samplenumber = 0;
  453. }
  454.  
  455.  
  456. uint32 SubbandLayer2::get_allocationlength (Header *header)
  457. {
  458.   uint32 channel_bitrate = header->bitrate_index ();
  459.  
  460.   // calculate bitrate per channel:
  461.   if (header->mode () != single_channel)
  462.     if (channel_bitrate == 4)
  463.       channel_bitrate = 1;
  464.     else
  465.       channel_bitrate -= 4;
  466.  
  467.   if (channel_bitrate == 1 || channel_bitrate == 2)
  468.     // table 3-B.2c or 3-B.2d
  469.     if (subbandnumber <= 1)
  470.       return 4;
  471.     else
  472.       return 3;
  473.   else
  474.     // tables 3-B.2a or 3-B.2b
  475.     if (subbandnumber <= 10)
  476.       return 4;
  477.     else if (subbandnumber <= 22)
  478.       return 3;
  479.     else
  480.       return 2;
  481. }
  482.  
  483.  
  484. void SubbandLayer2::prepare_sample_reading (Header *header, uint32 allocation,
  485.     const real **groupingtable, real *factor, uint32 *codelength, real *c, real *d)
  486. {
  487.   uint32 channel_bitrate = header->bitrate_index ();
  488.  
  489.   // calculate bitrate per channel:
  490.   if (header->mode () != single_channel)
  491.     if (channel_bitrate == 4)
  492.       channel_bitrate = 1;
  493.     else
  494.       channel_bitrate -= 4;
  495.  
  496.   if (channel_bitrate == 1 || channel_bitrate == 2)
  497.   {
  498.     // table 3-B.2c or 3-B.2d
  499.     *groupingtable = table_cd_groupingtables[allocation];
  500.     *factor = table_cd_factor[allocation];
  501.     *codelength = table_cd_codelength[allocation];
  502.     *c = table_cd_c[allocation];
  503.     *d = table_cd_d[allocation];
  504.   }
  505.   else
  506.   {
  507.     // tables 3-B.2a or 3-B.2b
  508.     if (subbandnumber <= 2)
  509.     {
  510.       *groupingtable = table_ab1_groupingtables[allocation];
  511.       *factor = table_ab1_factor[allocation];
  512.       *codelength = table_ab1_codelength[allocation];
  513.       *c = table_ab1_c[allocation];
  514.       *d = table_ab1_d[allocation];
  515.     }
  516.     else
  517.     {
  518.       *groupingtable = table_ab234_groupingtables[allocation];
  519.       if (subbandnumber <= 10)
  520.       {
  521.     *factor = table_ab2_factor[allocation];
  522.     *codelength = table_ab2_codelength[allocation];
  523.     *c = table_ab2_c[allocation];
  524.     *d = table_ab2_d[allocation];
  525.       }
  526.       else if (subbandnumber <= 22)
  527.       {
  528.     *factor = table_ab3_factor[allocation];
  529.     *codelength = table_ab3_codelength[allocation];
  530.     *c = table_ab3_c[allocation];
  531.     *d = table_ab3_d[allocation];
  532.       }
  533.       else
  534.       {
  535.     *factor = table_ab4_factor[allocation];
  536.     *codelength = table_ab4_codelength[allocation];
  537.     *c = table_ab4_c[allocation];
  538.     *d = table_ab4_d[allocation];
  539.       }
  540.     }
  541.   }
  542. }
  543.  
  544.  
  545. void SubbandLayer2::read_allocation (Ibitstream *stream, Header *header, Crc16 *crc)
  546. {
  547.   register uint32 length = get_allocationlength (header);
  548.   allocation = stream->get_bits (length);
  549.   if (crc)
  550.     crc->add_bits (allocation, length);
  551. }
  552.  
  553.  
  554. void SubbandLayer2::read_scalefactor_selection (Ibitstream *stream, Crc16 *crc)
  555. {
  556.   if (allocation)
  557.   {
  558.     scfsi = stream->get_bits (2);
  559.     if (crc)
  560.       crc->add_bits (scfsi, 2);
  561.   }
  562. }
  563.  
  564.  
  565. void SubbandLayer2::read_scalefactor (Ibitstream *stream, Header *header)
  566. {
  567.   if (allocation)
  568.   {
  569.     switch (scfsi)
  570.     {
  571.       case 0:
  572.     scalefactor1 = scalefactors[stream->get_bits (6)];
  573.     scalefactor2 = scalefactors[stream->get_bits (6)];
  574.     scalefactor3 = scalefactors[stream->get_bits (6)];
  575.     break;
  576.       case 1:
  577.     scalefactor1 = scalefactor2 = scalefactors[stream->get_bits (6)];
  578.     scalefactor3 = scalefactors[stream->get_bits (6)];
  579.     break;
  580.       case 2:
  581.     scalefactor1 = scalefactor2 = scalefactor3 = scalefactors[stream->get_bits (6)];
  582.     break;
  583.       case 3:
  584.     scalefactor1 = scalefactors[stream->get_bits (6)];
  585.     scalefactor2 = scalefactor3 = scalefactors[stream->get_bits (6)];
  586.     break;
  587.     }
  588.     prepare_sample_reading (header, allocation, &groupingtable,
  589.                 &factor, &codelength, &c, &d);
  590.   }
  591. }
  592.  
  593.  
  594. bool SubbandLayer2::read_sampledata (Ibitstream *stream)
  595. {
  596.   if (allocation)
  597.     if (groupingtable)
  598.     {
  599.       uint32 samplecode = stream->get_bits (codelength);
  600. #ifdef DEBUG
  601.       if (samplecode == (1 << codelength) - 1)
  602.     cerr << "WARNING: stream contains an illegal subband sample!\n";  // MPEG-stream is corrupted!
  603. #endif
  604.       // create requantized samples:
  605.       samplecode += samplecode << 1;
  606.       register real *target = samples;
  607.       register const real *source = groupingtable + samplecode;
  608.       *target++ = *source++;
  609.       *target++ = *source++;
  610.       *target = *source;
  611.       // memcpy (samples, groupingtable + samplecode, 3 * sizeof (real));
  612.     }
  613.     else
  614.     {
  615.       samples[0] = real (stream->get_bits (codelength)) * factor - 1.0;
  616.       samples[1] = real (stream->get_bits (codelength)) * factor - 1.0;
  617.       samples[2] = real (stream->get_bits (codelength)) * factor - 1.0;
  618. #ifdef DEBUG
  619.       if (samples[0] == (1 << codelength) - 1)
  620.     cerr << "WARNING: stream contains an illegal subband sample!\n";  // MPEG-stream is corrupted!
  621.       if (samples[1] == (1 << codelength) - 1)
  622.     cerr << "WARNING: stream contains an illegal subband sample!\n";  // MPEG-stream is corrupted!
  623.       if (samples[2] == (1 << codelength) - 1)
  624.     cerr << "WARNING: stream contains an illegal subband sample!\n";  // MPEG-stream is corrupted!
  625. #endif
  626.     }
  627.  
  628.   samplenumber = 0;
  629.   if (++groupnumber == 12)
  630.     return True;
  631.   else
  632.     return False;
  633. }
  634.  
  635.  
  636. bool SubbandLayer2::put_next_sample (e_channels channels,
  637.                      SynthesisFilter *filter1, SynthesisFilter *)
  638. {
  639. #ifdef DEBUG
  640.   if (samplenumber >= 3)
  641.   {
  642.     // don't call put_next_sample if the previous call returned True;
  643.     cerr << "Illegal call to SubbandLayer2::put_next_sample()!\n";
  644.     exit (1);
  645.   }
  646. #endif
  647.   if (allocation && channels != right)
  648.   {
  649.     register real sample = samples[samplenumber];
  650.  
  651.     if (!groupingtable)
  652.       sample = (sample + d) * c;
  653.     if (groupnumber <= 4)
  654.       sample *= scalefactor1;
  655.     else if (groupnumber <= 8)
  656.       sample *= scalefactor2;
  657.     else
  658.       sample *= scalefactor3;
  659. #ifdef DEBUG
  660.     if (sample < -1.0 || sample > 1.0)
  661.       cerr << "WARNING: rescaled subband sample is not in [-1.0, 1.0]\n";
  662.       // this should never occur
  663. #endif
  664.     filter1->input_sample (sample, subbandnumber);
  665.   }
  666.  
  667.   if (++samplenumber == 3)
  668.     return True;
  669.   else
  670.     return False;
  671. }
  672.  
  673.  
  674.  
  675. /******************************/
  676. /*** Intensity Stereo Class ***/
  677. /******************************/
  678.  
  679. SubbandLayer2IntensityStereo::SubbandLayer2IntensityStereo (uint32 subbandnumber)
  680. : SubbandLayer2 (subbandnumber)
  681. {
  682. }
  683.  
  684.  
  685. void SubbandLayer2IntensityStereo::read_scalefactor_selection (Ibitstream *stream, Crc16 *crc)
  686. {
  687.   if (allocation)
  688.   {
  689.     scfsi = stream->get_bits (2);
  690.     channel2_scfsi = stream->get_bits (2);
  691.     if (crc)
  692.     {
  693.       crc->add_bits (scfsi, 2);
  694.       crc->add_bits (channel2_scfsi, 2);
  695.     }
  696.   }
  697. }
  698.  
  699.  
  700. void SubbandLayer2IntensityStereo::read_scalefactor (Ibitstream *stream, Header *header)
  701. {
  702.   if (allocation)
  703.   {
  704.     SubbandLayer2::read_scalefactor (stream, header);
  705.     switch (channel2_scfsi)
  706.     {
  707.       case 0:
  708.     channel2_scalefactor1 = scalefactors[stream->get_bits (6)];
  709.     channel2_scalefactor2 = scalefactors[stream->get_bits (6)];
  710.     channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  711.     break;
  712.       case 1:
  713.     channel2_scalefactor1 = channel2_scalefactor2 = scalefactors[stream->get_bits (6)];
  714.     channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  715.     break;
  716.       case 2:
  717.     channel2_scalefactor1 = channel2_scalefactor2 =
  718.     channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  719.     break;
  720.       case 3:
  721.     channel2_scalefactor1 = scalefactors[stream->get_bits (6)];
  722.     channel2_scalefactor2 = channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  723.     break;
  724.     }
  725.   }
  726. }
  727.  
  728.  
  729. bool SubbandLayer2IntensityStereo::put_next_sample (e_channels channels,
  730.     SynthesisFilter *filter1, SynthesisFilter *filter2)
  731. {
  732. #ifdef DEBUG
  733.   if (samplenumber >= 3)
  734.   {
  735.     // don't call put_next_sample if the previous call returned True;
  736.     cerr << "Illegal call to SubbandLayer2::put_next_sample()!\n";
  737.     exit (1);
  738.   }
  739. #endif
  740.   if (allocation)
  741.   {
  742.     register real sample = samples[samplenumber];
  743.  
  744.     if (!groupingtable)
  745.       sample = (sample + d) * c;
  746.     if (channels == both)
  747.     {
  748.       register float sample2 = sample;
  749.       if (groupnumber <= 4)
  750.       {
  751.     sample *= scalefactor1;
  752.     sample2 *= channel2_scalefactor1;
  753.       }
  754.       else if (groupnumber <= 8)
  755.       {
  756.     sample *= scalefactor2;
  757.     sample2 *= channel2_scalefactor2;
  758.       }
  759.       else
  760.       {
  761.     sample *= scalefactor3;
  762.     sample2 *= channel2_scalefactor3;
  763.       }
  764. #ifdef DEBUG
  765.       if (sample < -1.0 || sample > 1.0 || sample2 < -1.0 || sample2 > 1.0)
  766.     cerr << "WARNING: rescaled subband sample is not in [-1.0, 1.0]\n";
  767.     // this should never occur
  768. #endif
  769.       filter1->input_sample (sample, subbandnumber);
  770.       filter2->input_sample (sample2, subbandnumber);
  771.     }
  772.     else if (channels == left)
  773.     {
  774.       if (groupnumber <= 4)
  775.     sample *= scalefactor1;
  776.       else if (groupnumber <= 8)
  777.     sample *= scalefactor2;
  778.       else
  779.     sample *= scalefactor3;
  780. #ifdef DEBUG
  781.       if (sample < -1.0 || sample > 1.0)
  782.     cerr << "WARNING: rescaled subband sample is not in [-1.0, 1.0]\n";
  783.     // this should never occur
  784. #endif
  785.       filter1->input_sample (sample, subbandnumber);
  786.     }
  787.     else
  788.     {
  789.       if (groupnumber <= 4)
  790.     sample *= channel2_scalefactor1;
  791.       else if (groupnumber <= 8)
  792.     sample *= channel2_scalefactor2;
  793.       else
  794.     sample *= channel2_scalefactor3;
  795. #ifdef DEBUG
  796.       if (sample < -1.0 || sample > 1.0)
  797.     cerr << "WARNING: rescaled subband sample is not in [-1.0, 1.0]\n";
  798.     // this should never occur
  799. #endif
  800.       filter1->input_sample (sample, subbandnumber);
  801.     }
  802.   }
  803.  
  804.   if (++samplenumber == 3)
  805.     return True;
  806.   else
  807.     return False;
  808. }
  809.  
  810.  
  811.  
  812. /********************/
  813. /*** Stereo Class ***/
  814. /********************/
  815.  
  816. SubbandLayer2Stereo::SubbandLayer2Stereo (uint32 subbandnumber)
  817. : SubbandLayer2 (subbandnumber)
  818. {
  819. }
  820.  
  821.  
  822. void SubbandLayer2Stereo::read_allocation (Ibitstream *stream, Header *header, Crc16 *crc)
  823. {
  824.   uint32 length = get_allocationlength (header);
  825.   allocation = stream->get_bits (length);
  826.   channel2_allocation = stream->get_bits (length);
  827.   if (crc)
  828.   {
  829.     crc->add_bits (allocation, length);
  830.     crc->add_bits (channel2_allocation, length);
  831.   }
  832. }
  833.  
  834.  
  835. void SubbandLayer2Stereo::read_scalefactor_selection (Ibitstream *stream, Crc16 *crc)
  836. {
  837.   if (allocation)
  838.   {
  839.     scfsi = stream->get_bits (2);
  840.     if (crc)
  841.       crc->add_bits (scfsi, 2);
  842.   }
  843.   if (channel2_allocation)
  844.   {
  845.     channel2_scfsi = stream->get_bits (2);
  846.     if (crc)
  847.       crc->add_bits (channel2_scfsi, 2);
  848.   }
  849. }
  850.  
  851.  
  852. void SubbandLayer2Stereo::read_scalefactor (Ibitstream *stream, Header *header)
  853. {
  854.   SubbandLayer2::read_scalefactor (stream, header);
  855.   if (channel2_allocation)
  856.   {
  857.     switch (channel2_scfsi)
  858.     {
  859.       case 0:
  860.     channel2_scalefactor1 = scalefactors[stream->get_bits (6)];
  861.     channel2_scalefactor2 = scalefactors[stream->get_bits (6)];
  862.     channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  863.     break;
  864.       case 1:
  865.     channel2_scalefactor1 = channel2_scalefactor2 = scalefactors[stream->get_bits (6)];
  866.     channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  867.     break;
  868.       case 2:
  869.     channel2_scalefactor1 = channel2_scalefactor2 =
  870.     channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  871.     break;
  872.       case 3:
  873.     channel2_scalefactor1 = scalefactors[stream->get_bits (6)];
  874.     channel2_scalefactor2 = channel2_scalefactor3 = scalefactors[stream->get_bits (6)];
  875.     break;
  876.     }
  877.     prepare_sample_reading (header, channel2_allocation, &channel2_groupingtable, &channel2_factor,
  878.                 &channel2_codelength, &channel2_c, &channel2_d);
  879.   }
  880. }
  881.  
  882.  
  883. bool SubbandLayer2Stereo::read_sampledata (Ibitstream *stream)
  884. {
  885.   bool returnvalue = SubbandLayer2::read_sampledata (stream);
  886.  
  887.   if (channel2_allocation)
  888.     if (channel2_groupingtable)
  889.     {
  890.       uint32 samplecode = stream->get_bits (channel2_codelength);
  891. #ifdef DEBUG
  892.       if (samplecode == (1 << channel2_codelength) - 1)
  893.     cerr << "WARNING: stream contains an illegal subband sample!\n";  // MPEG-stream is corrupted!
  894. #endif
  895.       // create requantized samples:
  896.       samplecode += samplecode << 1;
  897.       register real *target = channel2_samples;
  898.       register const real *source = channel2_groupingtable + samplecode;
  899.       *target++ = *source++;
  900.       *target++ = *source++;
  901.       *target = *source;
  902.       // memcpy (channel2_samples, channel2_groupingtable + samplecode, 3 * sizeof (real));
  903.     }
  904.     else
  905.     {
  906.       channel2_samples[0] = real (stream->get_bits (channel2_codelength)) * channel2_factor - 1.0;
  907.       channel2_samples[1] = real (stream->get_bits (channel2_codelength)) * channel2_factor - 1.0;
  908.       channel2_samples[2] = real (stream->get_bits (channel2_codelength)) * channel2_factor - 1.0;
  909. #ifdef DEBUG
  910.       if (channel2_samples[0] == (1 << channel2_codelength) - 1)
  911.     cerr << "WARNING: stream contains an illegal subband sample!\n";  // MPEG-stream is corrupted!
  912.       if (channel2_samples[1] == (1 << channel2_codelength) - 1)
  913.     cerr << "WARNING: stream contains an illegal subband sample!\n";  // MPEG-stream is corrupted!
  914.       if (channel2_samples[2] == (1 << channel2_codelength) - 1)
  915.     cerr << "WARNING: stream contains an illegal subband sample!\n";  // MPEG-stream is corrupted!
  916. #endif
  917.     }
  918.   return returnvalue;
  919. }
  920.  
  921.  
  922. bool SubbandLayer2Stereo::put_next_sample (e_channels channels,
  923.                        SynthesisFilter *filter1, SynthesisFilter *filter2)
  924. {
  925.   bool returnvalue = SubbandLayer2::put_next_sample (channels, filter1, filter2);
  926.   if (channel2_allocation && channels != left)
  927.   {
  928.     register real sample = channel2_samples[samplenumber - 1];
  929.  
  930.     if (!channel2_groupingtable)
  931.       sample = (sample + channel2_d) * channel2_c;
  932.  
  933.     if (groupnumber <= 4)
  934.       sample *= channel2_scalefactor1;
  935.     else if (groupnumber <= 8)
  936.       sample *= channel2_scalefactor2;
  937.     else
  938.       sample *= channel2_scalefactor3;
  939. #ifdef DEBUG
  940.     if (sample < -1.0 || sample > 1.0)
  941.       cerr << "WARNING: rescaled subband sample is not in [-1.0, 1.0]\n";
  942.       // this should never occur
  943. #endif
  944.     if (channels == both)
  945.       filter2->input_sample (sample, subbandnumber);
  946.     else
  947.       filter1->input_sample (sample, subbandnumber);
  948.   }
  949.   return returnvalue;
  950. }
  951.